<template>
  <nav class="navbar"
       :class="{ 'navbar-scrolled': isScrolled }">
    <div class="nav-content">
      <router-link to="/"
                   class="logo">
        <span class="logo-text">Blog</span>
      </router-link>

      <div class="nav-links"
           :class="{ 'active': isMenuOpen }">
        <router-link to="/"
                     class="nav-link">首页</router-link>
        <router-link to="/articles"
                     class="nav-link">文章</router-link>
        <router-link to="/tags"
                     class="nav-link">标签</router-link>
        <router-link to="/about"
                     class="nav-link">关于</router-link>
      </div>

      <div class="nav-right">
        <div class="search-box">
          <input type="text"
                 placeholder="搜索文章..."
                 v-model="searchQuery"
                 @input="handleSearch">
        </div>
        <button class="menu-btn"
                @click="toggleMenu">
          <span></span>
          <span></span>
          <span></span>
        </button>
      </div>
    </div>
  </nav>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const isScrolled = ref(false);
const isMenuOpen = ref(false);
const searchQuery = ref('');

const handleScroll = () => {
  isScrolled.value = window.scrollY > 50;
};

const toggleMenu = () => {
  isMenuOpen.value = !isMenuOpen.value;
};

const handleSearch = () => {
  // 实现搜索逻辑
  if (searchQuery.value.length > 0) {
    router.push({
      path: '/search',
      query: { q: searchQuery.value }
    });
  }
};

onMounted(() => {
  window.addEventListener('scroll', handleScroll);
});

onUnmounted(() => {
  window.removeEventListener('scroll', handleScroll);
});
</script>

<style scoped>
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  padding: 1rem 2rem;
  transition: all 0.3s ease;
  background: transparent;
}

.navbar-scrolled {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.nav-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  text-decoration: none;
}

.logo-text {
  font-size: 1.5rem;
  font-weight: bold;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.nav-links {
  display: flex;
  gap: 2rem;
}

.nav-link {
  color: #fff;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s ease;
  position: relative;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 0;
  width: 0;
  height: 2px;
  background: #88ccff;
  transition: width 0.3s ease;
}

.nav-link:hover::after {
  width: 100%;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.search-box input {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  outline: none;
  transition: all 0.3s ease;
}

.search-box input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.search-box input:focus {
  background: rgba(255, 255, 255, 0.2);
}

.menu-btn {
  display: none;
  flex-direction: column;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
}

.menu-btn span {
  display: block;
  width: 25px;
  height: 2px;
  background: #fff;
  transition: all 0.3s ease;
}

@media (max-width: 768px) {
  .nav-links {
    position: fixed;
    top: 70px;
    left: 0;
    width: 100%;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.9);
    padding: 2rem;
    gap: 1rem;
    transform: translateY(-100%);
    opacity: 0;
    transition: all 0.3s ease;
  }

  .nav-links.active {
    transform: translateY(0);
    opacity: 1;
  }

  .menu-btn {
    display: flex;
  }

  .search-box {
    display: none;
  }
}
</style> 